package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

public class RegisterDateBase {
    private String dbdriver="com.mysql.jdbc.Driver";
    private String dburl="jdbc:mysql://localhost:3306/sctu-javaweb-2018?serverTimezone=UTC&characterEncoding=UTF-8";
    private String dbuser="root";
    private String dbpassword="123456";

    public void addUser(String username,Integer password)throws Exception{
        Connection connection=null;
        PreparedStatement preparedStatement=null;
        Class.forName(dbdriver);
        connection= DriverManager.getConnection(dburl,dbuser,dbpassword);

        String sql="INSERT ignore INTO user_information(username,password)" +
                "VALUES(?,?)";
        preparedStatement=connection.prepareStatement(sql);
        preparedStatement.setString(1,username);
        preparedStatement.setInt(2,password);
        preparedStatement.execute();
        connection.close();
        preparedStatement.close();

    }
}
